/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package me.uniauto.zz.cwl.web.hjrk;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import me.uniauto.zz.cwl.entity.hjrk.CwlSyrkHjrk;
import me.uniauto.zz.cwl.service.hjrk.CwlSyrkHjrkService;

/**
 * 户籍人口Controller
 * @author 王娜
 * @version 2019-02-18
 */
@Controller
@RequestMapping(value = "${adminPath}/cwl/hjrk/cwlSyrkHjrk")
public class CwlSyrkHjrkController extends BaseController {

	@Autowired
	private CwlSyrkHjrkService cwlSyrkHjrkService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public CwlSyrkHjrk get(String id, boolean isNewRecord) {
		return cwlSyrkHjrkService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("cwl:hjrk:cwlSyrkHjrk:view")
	@RequestMapping(value = {"list", ""})
	public String list(CwlSyrkHjrk cwlSyrkHjrk, Model model) {
		model.addAttribute("cwlSyrkHjrk", cwlSyrkHjrk);
		return "zz/cwl/hjrk/cwlSyrkHjrkList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("cwl:hjrk:cwlSyrkHjrk:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<CwlSyrkHjrk> listData(CwlSyrkHjrk cwlSyrkHjrk, HttpServletRequest request, HttpServletResponse response) {
		cwlSyrkHjrk.setPage(new Page<>(request, response));
		Page<CwlSyrkHjrk> page = cwlSyrkHjrkService.findPage(cwlSyrkHjrk);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("cwl:hjrk:cwlSyrkHjrk:view")
	@RequestMapping(value = "form")
	public String form(CwlSyrkHjrk cwlSyrkHjrk, Model model) {
		model.addAttribute("cwlSyrkHjrk", cwlSyrkHjrk);
		return "zz/cwl/hjrk/cwlSyrkHjrkForm";
	}

	/**
	 * 保存户籍人口
	 */
	@RequiresPermissions("cwl:hjrk:cwlSyrkHjrk:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated CwlSyrkHjrk cwlSyrkHjrk) {
		cwlSyrkHjrkService.save(cwlSyrkHjrk);
		return renderResult(Global.TRUE, text("保存户籍人口成功！"));
	}
	
	/**
	 * 删除户籍人口
	 */
	@RequiresPermissions("cwl:hjrk:cwlSyrkHjrk:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(CwlSyrkHjrk cwlSyrkHjrk) {
		cwlSyrkHjrkService.delete(cwlSyrkHjrk);
		return renderResult(Global.TRUE, text("删除户籍人口成功！"));
	}
	
}